#include<clutil.h>
#include<vector>
#define SIZE 1024
using namespace std;

#include<sys/types.h>
#define THREADS_PER_BLOCK 256

#include<CL/cl.h>

template<class T>
void execute(const T* const data, const unsigned count)
{
    initExecution("cpu");
    const unsigned size = count * sizeof(T);
      
    const unsigned nGLAs =  /* methodology to determine number og glas*/ 
    cl_mem dUvec = allocateDeviceMemory(data, size, CL_MEM_READ_ONLY);

    // states in global memory
    cl_mem dCount = allocateDeviceMemory(0, sizeof(T), 
                                                   CL_MEM_READ_WRITE);
    cl_mem dSum = allocateDeviceMemory(0,  sizeof(T), 
                                                   CL_MEM_READ_WRITE);
    compileProgram(0, "kernel.cl");
    createKernel("average");
    setKernelArg("average", 0, sizeof(cl_mem), &dUvec);
    setKernelArg("average", 1, sizeof(cl_mem), &dCount);
    setKernelArg("average", 2, sizeof(cl_mem), &dSum);
    // states in local memory
    setKernelArg("average", 3, sizeof(unsigned), 0);
    setKernelArg("average", 4, sizeof(unsigned), 0);

    size_t szLocalWorkSize = THREADS_PER_BLOCK;
    size_t szGlobalWorkSize = nGLAs * THREADS_PER_BLOCK;
    runKernel("average", szLocalWorkSize, szGlobalWorkSize); 
    
    waitForEvent();
    //copyFromDevice(dCount, count, nGLAs * sizeof(unsigned));
    //copyFromDevice(dSum, count, nGLAs * sizeof(unsigned));
    cleanup(); 
}

int
main()
{
}

